﻿import com.dinmax.isolution.*
import com.dinmax.flash.utilities.math.ColorUtils;
import flash.geom.ColorTransform;
import flash.geom.Transform;


class LightRGBGUI
extends MovieClip {
	
	private var device:LightRGB;
	private var listener:WindowDeviceGUI;
	
	function LightRGBGUI(){
		if(this._parent._parent instanceof WindowDeviceGUI)	this.listener = WindowDeviceGUI(this._parent._parent);
		return;
	}
		
	public function getDevice():LightRGB{
		return this.device;
	}
	public function setDevice(newDevice:LightRGB):Void{
		this.device = newDevice;
		this.refresh();
		return;
	}
	
	public function setSelected(b:Boolean):Void {
		
		if(b){
			this.gotoAndStop(2);
			listener.showDeviceView(device);			
			
		} else {
			this.gotoAndStop(1);
			refresh();
		}
		return;
	}
	
	public function getSelected():Boolean{
		return (this._currentframe == 2);
	}
	
	public function refresh():Void {
		
		this["txt_title"].text = this.device.getName();
		this["txt_group"].text = this.device.getGroup();
		var val:Object = this.device.getValue();
		
		trace("LightRGBGUI | refresh | val= "+val.r+","+val.g+","+val.b);
		var colorTrans:ColorTransform = new ColorTransform();
		colorTrans.rgb = ColorUtils.rgb2hex(val.r, val.g, val.b);
		(colorTrans.rgb == 0) ? this["mcState"].gotoAndStop(2) : this["mcState"].gotoAndStop(1);
		var trans:Transform = new Transform(this["mcColorState"]);
		trans.colorTransform = colorTrans;
				 
		return;
	}
	
	
}